<?php

require_once($controllerDir . '/pclinkhash.php');
require_once($modelDir . '/loginmodel.php');
require_once($controllerDir . '/controller.php');
require_once($viewDir . '/loginview.php');

define('NEW_SESSION',     001 );
define('OPENING_SESSION', 002 );
define('OPENED_SESSION',  003 );
define('CLOSED_SESSION',  004 );
define('EXPIRED_SESSION', 005 );


class LoginController  extends controller {

  protected $linkController;
  protected $loginmodel;
  protected $sessionState;
  protected $login_view;

  public function __construct($login_model) {
    parent::__construct();
    $this->linkController = PCLinkHash::getInstance();
    $this->loginmodel     = $login_model;
    $this->login_view     = new loginview();
    $this->sessionState   = NEW_SESSION;
    $this->linkController->addPage($a_login_controller);
  }

  public function getActionControllerName() {
    return "login_controller";
  }

  public function getSessionState() {
   return $this->sessionState;
  }

  public function getLoginModel() {
    return $this->loginmodel;
  }

  public function invoke() {
    if($this->sessionState == NEW_SESSION) {
      $this->viewLoginSession();
      $this->sessionState = OPENING_SESSION;
    } else if($this->sessionState == OPENING_SESSION){
      $this->openingSessionHandler();
    } else if($this->sessionState == OPENED_SESSION){
      $this->openedSessionHandler();
    }
    return True;
  }

  protected function openingSessionHandler() {
/*    echo $_GET["mkey"];
    echo "<br/> status: ";
    echo $_REQUEST['action'];
    echo "<br/> status111: ";
    echo $_GET['status'];
    echo "<br/> status222: ";
    echo $_GET['action'];
    echo "<br/> status333: ";
    echo $_POST['submit'];
    echo "<br/> status444: ";
    echo $_POST['action'];
    echo "<br/> status555: ";
    echo $_POST['login_password'];
    echo "<br/> status777: ";
    echo $_POST['login_username'];
    echo "<br/> status888: ";
    echo $_GET['username'];*/
  }

  protected function openedSessionHandler() {
  }

  protected function viewLoginSession() {
   global $viewDir;
    $this->login_view->setLinkController($this->linkController);
    $this->login_view->setViewDirectory($viewDir);
    $this->login_view->setActionControllerName($this->getActionControllerName());
    $this->login_view->invoke();
/*   include $viewDir . '/loginview.php';*/
  }

  protected function closeSession() {
  }
}

?>
